﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp.WinForms;

namespace CefSharp.MinimalExample.WinForms.Handler
{
    public class KeyboardHandler:IKeyboardHandler
    {

        private static bool preShowMenu = false;
        public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
        {
            return false;
        }

        public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
        {
            //const int VK_F5 = 0x74;
            //if (windowsKeyCode == VK_F5)
            //{
            //    browser.Reload(); //此处可以添加想要实现的代码段

            //}

            if (preShowMenu && windowsKeyCode == 123)
            {
                preShowMenu = false;
                ((StarupForm) ((ChromiumWebBrowser) browserControl).Parent.Parent).MenuShow();
                MessageBox.Show("工具开启", "消息");
            }
            
            preShowMenu = modifiers == CefEventFlags.ControlDown;
            

            //if (_hiddenKey.Length >= 8)
            //{
            //    _hiddenKey = _hiddenKey.Substring(_hiddenKey.Length - 7, 7);
            //}
            //var key = (char)windowsKeyCode;
            //if (key.Length == 1)
            //{
            //    _hiddenKey = _hiddenKey + key;
            //}

            //if (_hiddenKey.Contains("showmenu"))
            //{
            //    MenuShow();
            //    MessageBox.Show("工具开启", "消息");
            //}
            //if (_hiddenKey.Contains("hidemenu"))
            //{

            //    MenuHide();
            //}
            return false;
        }
    }
}
